package com.cdck.safe.dete.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdck.safe.dete.common.result.PageResult;
import com.cdck.safe.dete.common.result.Result;
import com.cdck.safe.dete.model.entity.ResourceRecord;
import com.cdck.safe.dete.model.query.ResourceRecordQuery;
import com.cdck.safe.dete.model.vo.ResourceRecordVO;
import com.cdck.safe.dete.service.ResourceRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * (ResourceRecord)表控制层
 *
 * @author wp
 * @since 2024-05-18 14:35:52
 */
@Api(value = "resourceRecord")
@RestController
@RequestMapping("resourceRecord")
@RequiredArgsConstructor
public class ResourceRecordController {

    private final ResourceRecordService resourceRecordService;


    @ApiOperation(value = "分页列表")
    @GetMapping("/page")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "queryParams"  ,value ="查询条件" )
    })
    public PageResult<ResourceRecordVO> queryByPage(ResourceRecordQuery queryParams) {
        IPage<ResourceRecordVO> result = resourceRecordService.queryByPage(queryParams);
        return PageResult.success(result);

    }

    @ApiOperation(value = "获取待审核记录列表")
    @GetMapping("/list")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "queryParams"  ,value ="查询条件" )
    })
    public PageResult<ResourceRecordVO> List(ResourceRecordQuery queryParams) {
        IPage<ResourceRecordVO> result = resourceRecordService.queryList(queryParams);
        return PageResult.success(result);

    }

    @ApiOperation(value = "表单数据")
    @GetMapping("/{id}/form")
    public Result<ResourceRecord> getResourceRecordForm(
           @PathVariable Long id
    ) {
        ResourceRecord formData = resourceRecordService.getResourceRecordFormData(id);
        return Result.success(formData);
    }


    /**
     * 新增数据
     *
     * @param resourceRecord 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增")
    @PostMapping
    public Result add(
        @RequestBody @Valid
        ResourceRecord resourceRecord
        ) {
        boolean result = this.resourceRecordService.saveResourceRecord(resourceRecord);
        return Result.judge(result);
    }

    @ApiOperation(value = "修改")
    @PutMapping(value = "/{id}")
    public Result updateResourceRecord(
            @PathVariable Long id,
            @RequestBody @Validated ResourceRecord resourceRecord) {
        boolean result = resourceRecordService.updateResourceRecord(id, resourceRecord);
        return Result.judge(result);
    }


    @ApiOperation(value = "删除数据")
    @DeleteMapping("/{ids}")
    public Result deleteResourceRecords(
             @PathVariable String ids
    ) {
        boolean result = resourceRecordService.deleteResourceRecords(ids);
        return Result.judge(result);
    }

    @ApiOperation(value = "驳回申请")
    @PutMapping(value = "/overrule")
    public Result overrule(
            @RequestBody @Validated ResourceRecord resourceRecord) {
        boolean result = resourceRecordService.overrule(resourceRecord);
        return Result.judge(result);
    }

    @ApiOperation(value = "申请通过")
    @GetMapping(value = "/pass/{id}")
    public Result pass(
            @PathVariable("id") Long id) {
        boolean result = resourceRecordService.pass(id);
        return Result.judge(result);
    }

    @ApiOperation(value = "取消预约")
    @GetMapping(value = "/cancel/{id}")
    public Result cancel(
            @PathVariable("id") Long id) {
        boolean result = resourceRecordService.cancel(id);
        return Result.judge(result);
    }

    @ApiOperation(value = "预约完成")
    @GetMapping(value = "/finish/{id}")
    public Result finish(
            @PathVariable("id") Long id) {
        boolean result = resourceRecordService.finish(id);
        return Result.judge(result);
    }

    @ApiOperation(value = "查询某人的所有记录")
    @GetMapping(value = "/my")
    public Result<List<ResourceRecordVO>> finish()
    {
        List<ResourceRecordVO> result = resourceRecordService.myRecord();
        return Result.success(result);
    }


}

